#ifndef VIEW_H
#define VIEW_H

#include "schemacomponent.h"

#include <string>

using namespace std;

// Forward declarations.
class SchemaComponentFormula;
class ColumnList;
class Column;
class QueryTree;

/*
    Class: View
    Represents an SQL view.
*/
class View : public SchemaComponent
{
    /* Section: public */
    public:
        /*
            Constructor: Default constructor.
            Initializes the object.

            Parameters:
                name - Name of the view ("" by default).

            See also:
                SchemaComponent
        */
        View(ColumnList * columns = NULL, QueryTree * query =NULL, const string & name = "");

        /*
            Destructor: Default destructor.
            Destroy the object.
        */
        virtual ~View();

        /*
            Constructor: Copy Constructor.
            Initializes the object as a copy of other View object.

            Parameters:
                other - View to copy from.
        */
        View(const View& other);

        /*
            Method: setColumnList
            Set a list of columns to this view. Destroy the previous list of columns if any.

            Parameters:
                columns -   Type: ColumList
                            List of columns to set

            See also:
                ColumnList
        */
        void setColumnList(ColumnList * columns);

        /*
            Method: setQueryTree
            Set a query tree to this view. Destroy the previous query tree if any.

            Parameters:
                query   -   Type: QueryTree
                            QueryTree to set.

            See also:
                QueryTree
        */
        void setQueryTree(QueryTree * query);

        /*
            Method: getColumnList
            Returns:
                A const pointer to the list of columns of the view.

            See also:
                ColumnList
        */
        ColumnList * getColumnList() const;

        /*
            Method: getQueryTree
            Returns:
                A const pointer to the query expression of the view.

            See also:
                QueryTree.
        */
        QueryTree * getQueryTree() const;

        /*
            Method: addColumn
            Adds a column to the ColumnList of the view.

            Parameters:
                column  - Column to add.

            See also:
                Column
        */
        void addColumn(Column * column);

        /*
            Method: addColumn
            Adds a column with the name given.

            Parameters:
                name    -   Name of the column
        */
        void addColumn(const string & name);

        /*
            Method: toString

            See also:
                AbstractTable.
        */
        virtual string toString();

	/*Method getColumns
	 * Returns:
	 * 	The list of the names of the columns
	 */

	virtual ColumnList * getColumns();
        /*
            Method: clone
            Returns:
                A pointer to a clone of this object.
        */
        virtual SchemaComponent * clone();

    /* Section: private */
    private:
        /*
            Variable: columns
            Type: ColumnList
            List of columns.

            See also:
                ColumnList
        */
        ColumnList * columns;

        /*
            Variable: query
            Type: QueryTree
            Query of the View.

            See also:
                QueryTree
        */
        QueryTree * query;
};

#endif // VIEW_H
